<template>
  <div class='icons'>
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icon" v-for="item of page" :key="item.id">
          <div class="icon-img">
            <img class="img-content" :src="item.imgUrl"/>
            <p class="icon-des">{{item.des}}</p>
          </div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      },
      iconsList: [{
        'id': '001',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '002',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '003',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '004',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '005',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '006',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '007',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '008',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }, {
        'id': '009',
        'imgUrl': 'http://fuss10.elemecdn.com/7/d8/a867c870b22bc74c87c348b75528djpeg.jpeg?imageMogr/format/webp/thumbnail/!90x90r/gravity/Center/crop/90x90/',
        'des': '地方菜系'
      }
      ]
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconsList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang='stylus' scoped>
  @import '~styles/varibles.styl';
  .icons >>> .swiper-container
    height 0
    padding-bottom 50%
  .icons {
    overflow: hidden;
    height: 0;
    padding-bottom: 50%;

    .icon {
      position: relative;
      overflow: hidden;
      float: left;
      width: 25%;
      height: 0;
      padding-bottom: 25%;

      .icon-img {
        position: absolute;
        top: 0;
        right: 0;
        left: 0;
        bottom: 0.44rem;
        padding: 0.1rem;
        box-sizing: border-box;

        .img-content {
          display: block;
          margin: 0 auto;
          height: 100%;
        }
      }

      .icon-des {
        position: relative;
        right: 0;
        left: 0;
        bottom: 0;
        height: 0.44rem;
        line-height: 0.44rem;
        color: $DarkColor;
        text-align: center;
      }
    }
  }
</style>
